package com.chefu.body.controller;

import com.chefu.body.pojo.CarDetail;
import com.chefu.body.pojo.CarOwner;
import com.chefu.body.service.CarOwnerService;
import com.chefu.common.pojo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class CarOwnerController {

    @Autowired
    private CarOwnerService carOwnerService;

    /**
     * 分页查询车主信息
     *
     * @param page
     * @param pageSize
     * @param carOwner
     * @return
     */
    @GetMapping("/carowner/page")
    public ResponseEntity<PageResult<CarOwner>> queryCarOwnerByPage(
            @RequestParam(value = "page", defaultValue = " 1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestBody CarOwner carOwner
    ) {
        log.info("【执行开始：分页查询车主信息】");
        PageResult<CarOwner> pageResult = carOwnerService.queryCarOwnerByPage(page, pageSize, carOwner);
        log.info("【执行成功：分页查询车主信息】");
        return ResponseEntity.ok(pageResult);
    }
    /**
     * 根据车主id查询查询所属车辆详细信息
     * @param carownerId
     * @return
     */
    @GetMapping("/carowner/{cardetail}")
    public ResponseEntity<List<CarDetail>> queryCarDetileByCarOwnerId(@PathVariable("cardetail") Long  carownerId) {
        log.info("【执行开始：根据车主id查询查询所属车辆详细信息】"+"id:"+carownerId);
        List<CarDetail> carDetails = carOwnerService.queryCarDetileByCarOwnerId(carownerId);
        log.info("【执行成功：根据车主id查询查询所属车辆详细信息】"+"id:"+carownerId);
        return ResponseEntity.ok(carDetails);
    }
}
